﻿using Protocol.OUSProtocol.Model;
using System;
using TcpServer.ClientServer;
using TcpServer.OUServer;

namespace OUS_HUB
{
    /// <summary>
    /// 调试模式
    /// </summary>
    public enum DebugModel
    {
        /// <summary>
        /// debug模式
        /// </summary>
        Debug=0,
        /// <summary>
        /// release模式
        /// </summary>
        Release=1
    }

    public class Ous
    {
        /// <summary>
        /// 地址
        /// </summary>
        public string DAddrReverse { get; set; }

        //public IPEndPoint ipep { get; set; }

        public OUServerProtocolSession session { get; set; }

        public string Version { get; set; }
        public DateTime VersionDate { get; set; }

        /// <summary>
        /// 特殊标识，用于处理特殊操作
        /// </summary>
        public string SpecialFlag { set; get; }
        /// <summary>
        /// 接口请求的设置参数
        /// </summary>
        public Params InterfaceParams{get;set;}

        /// <summary>
        /// 固件升级标志
        /// </summary>
        public bool IsUpdating { get; set; }

        /// <summary>
        /// 固件传输索引
        /// </summary>
        public int UpdatingPartsIndex { get; set; }


        public string QCCID { get; set; }

        /// <summary>
        /// 0=氨气探头或1=CO2
        /// </summary>
        public string NH3CO2 { get; set; }

    }

    public class WebRequest
    {
        public ClientServerSession Session { get; set; }

        /// <summary>
        /// 请求的参数
        /// </summary>
        public string RequestJsonData { get; set; }

        public int dtype { get; set; }
        public int daddr { get; set; }
        public string func { get; set; }

        /// <summary>
        /// 已超时?
        /// </summary>
        public bool TimeOut { get; set; }


        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="session">会话</param>
        /// <param name="timeout">超时时间单位秒</param>
        public WebRequest(ClientServerSession session, int timeout)
        {
            this.Session = session;
            this.TimeOut = false;
            this.RequestJsonData = string.Empty;
            System.Timers.Timer timer = new System.Timers.Timer(timeout * 1000);
            timer.Elapsed += Timer_Elapsed;
            timer.AutoReset = false;
            timer.Enabled = true;
        }

        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TimeOut = true;
        }
    }

    public class WebRequestData
    {
        public string appid { get; set; }
        public string sign { get; set; }
        public string nonce { get; set; }
        public string timestamp { get; set; }

        public string func { get; set; }

        public WebRequestDataContentData data { get; set; }
    }

    public class WebRequestDataContentData
    {
        /// <summary>
        /// 0:欧式环控器 其他类型后续支持
        /// </summary>
        public int dtype { get; set; }
        public int daddr { get; set; }
        public object content { get; set; }
    }

    public class WebResParams
    {
        /// <summary>
        /// 0:欧式环控器 其他类型后续支持
        /// </summary>
        public int dtype { get; set; }
        public int daddr { get; set; }
        public Params content { get; set; }
    }

    public class WebResData
    {
        /// <summary>
        /// 0:成功，1:授权错误 2:其他错误，参考resdata
        /// </summary>
        public int errorcode { get; set; }
        public object resdata { get; set; }
    }

    public class Config
    {
        public int port { get; set; }
        public int timeInterval { get; set; }

        public string intervaltype { get; set; }

        public string interface_url { get; set; }

        public string interface_appid { get; set; }

        public string interface_sign { get; set; }



        public Config()
        {
            //默认配置
            port = 30201;
            timeInterval = 30;
            intervaltype = "分";
            interface_url = "http://api.junciot.com/docking/api/data/ReceiveData";
            interface_appid = "505799BF";
            interface_sign = "3F28FFA2FC33CAED60A34AAE899CA0BF";
        }
    }

    public class InterfaceRes
    {
        public short ErrorCode { get; set; }
        public string ErrorMessage { get; set; }
    }

    public class Firmware
    {
        public string LocalFileName { get; set; }
        public long LocalFileSize { get; set; }
        public long LocalTotalPart { get; set; }
        public string LocalCrc16Hex { get; set; }
        public byte[] Content { get; set; }
    }

    public class RemoteFirmware
    {
        public string RemoteFileName { get; set; }
        public string RemoteFileSize { get; set; }
        public string RemoteFileCrc16 { get; set; }
        public string RemoteTotalPart { get; set; }
        public string RemoteRecievePart { get; set; }
    }
}
